package com.example.base.validation.component;

import com.example.base.validation.annation.NonEmptyArray;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.List;

public class NonEmptyArrayValidator implements ConstraintValidator<NonEmptyArray, List> {

    private boolean required = false;

    @Override
    public void initialize(NonEmptyArray constraintAnnotation) {
        // 进行初始化
        required = constraintAnnotation.required();
    }

    @Override
    public boolean isValid(List list, ConstraintValidatorContext constraintValidatorContext) {
        return list != null && list.size() > 0;
    }

}
